package com.heima.kafka.boot.controller;


import com.alibaba.fastjson.JSON;
import com.heima.kafka.boot.pojos.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    private KafkaTemplate kafkaTemplate;

    @GetMapping("hello")
    public String hello() {
        kafkaTemplate.send("kafka666","黑马程序员");
        return "okk";
    }
    @GetMapping("object")
    public String Object(){
        User user = new User();
        user.setAge(18);
        user.setUsername("张三");
        String userJson = JSON.toJSONString(user);
        kafkaTemplate.send("user",userJson);
        return "okkkk";
    }
}
